package com.css.zfzx.fwsjcj.modules.statistics.fw.repository;

import com.css.zfzx.fwsjcj.modules.statistics.fw.entity.FwAreaBuildingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public interface FwAreaBuildingReqository extends JpaRepository<FwAreaBuildingEntity, String> {

    @Query(nativeQuery = true, value = "select count(*) from fw_area_building where del_flag = 0 and  district_name = :districtName  and division_level = :divisionLevel")
    int queryFwDateByDistrict(@Param("districtName") String districtName,@Param("divisionLevel") String divisionLevel);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_area_building set all_building_area = :allBuildingArea,amendatory_all_building_area = :amendatoryAllBuildingArea,area_is_open = :areaIsOpen," +
            "all_building_count = :allBuildingCount,amendatory_all_building_count = :amendatoryAllBuildingCount,count_is_open = :countIsOpen," +
            "updator_id = :userId, update_time = :date" +
            " WHERE district_name = :districtName and division_level=1")
    void updateDataByDistrict(@Param("districtName") String districtName,
                              @Param("allBuildingArea") Double allBuildingArea, @Param("amendatoryAllBuildingArea") Double amendatoryAllBuildingArea, @Param("areaIsOpen") String areaIsOpen,
                              @Param("allBuildingCount") int allBuildingCount, @Param("amendatoryAllBuildingCount") int amendatoryAllBuildingCount, @Param("countIsOpen") String countIsOpen,
                              @Param("userId") String userId, @Param("date") Date date);

    @Query(nativeQuery = true, value = "select count(*) from fw_area_building where del_flag = 0 and  district_name = :districtName and belongto_city = :belongtoCity and division_level = 2")
    int queryFwDateByCity(@Param("districtName") String districtName, @Param("belongtoCity") String belongtoCity);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_area_building set all_building_area = :allBuildingArea,amendatory_all_building_area = :amendatoryAllBuildingArea,area_is_open = :areaIsOpen," +
            "all_building_count = :allBuildingCount,amendatory_all_building_count = :amendatoryAllBuildingCount,count_is_open = :countIsOpen," +
            "updator_id = :userId, update_time = :date" +
            " WHERE district_name = :districtName and belongto_city = :belongtoCity  and division_level=2")
    void updateDataByCity(@Param("districtName") String districtName, @Param("belongtoCity") String belongtoCity,
                          @Param("allBuildingArea") Double allBuildingArea, @Param("amendatoryAllBuildingArea") Double amendatoryAllBuildingArea, @Param("areaIsOpen") String areaIsOpen,
                          @Param("allBuildingCount") int allBuildingCount, @Param("amendatoryAllBuildingCount") int amendatoryAllBuildingCount, @Param("countIsOpen") String countIsOpen,
                          @Param("userId") String userId, @Param("date") Date date);




}
